package xyz.liuyuhe.StudySpring.ch7.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DBQueryProxy implements InvocationHandler{
    private Object target;
    
    public Object createQuery(Object target){
        this.target = target;
        return Proxy.newProxyInstance(
                this.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("query ID:"+args[0]);
        return method.invoke(target, args);
    }

}
